/**
 * FileFind - ftp/shares indexing and search php engine
 * Module: common
 * Description: Common classes
 * Copyright (c) 2003-2010 Rage Steel, www.gt2.ru
 */
package ru.ffind.common.model;

import java.util.List;

import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;

/**
 * Host name + path items, used in browsing directories.
 * IDEA There must be HostPathNames And HostPathEntries
 *
 * @author Rage Steel
 */
public class HostPath {

	public static final HostPath EMPTY = 
		new HostPath("", ImmutableList.<String>of());  
	
	private final String hostName;
	
	private final ImmutableList<String> pathItems;

	public static HostPath of(String hostName, ImmutableList<String> pathItems) {
		String checkedHostname = Preconditions.checkNotNull(hostName);
		ImmutableList<String> checkedPathItems = Preconditions.checkNotNull(pathItems);
		return new HostPath(checkedHostname, checkedPathItems);
	}
	
	public static HostPath of(String hostName, List<String> pathItems) {
		String checkedHostname = Preconditions.checkNotNull(hostName);
		List<String> checkedPathItems = Preconditions.checkNotNull(pathItems);
		return new HostPath(checkedHostname, ImmutableList.copyOf(checkedPathItems));
	}
	
	public static HostPath of(String hostName, String... pathItems) {
		String checkedHostname = Preconditions.checkNotNull(hostName);
		String[] checkedPathItems = Preconditions.checkNotNull(pathItems);
		return new HostPath(checkedHostname, ImmutableList.copyOf(checkedPathItems));
	}
		
	public String getHostName() {
		return hostName;
	}
	
	public ImmutableList<String> getPathItems() {
		return pathItems;
	}
	
	@Override
	public boolean equals(Object object) {
		if (object instanceof HostPath) {
			HostPath that = (HostPath) object;
			return Objects.equal(this.hostName, that.hostName)
				&& Objects.equal(this.pathItems, that.pathItems);
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		return Objects.hashCode(hostName, pathItems);
	}
	
	@Override
	public String toString() {
		return Objects.toStringHelper(this)
			.add("hostName", hostName)
			.add("pathItems", pathItems)
			.toString();
	}
	
	private HostPath(String hostName, ImmutableList<String> pathItems) {
		this.hostName = hostName;
		this.pathItems = pathItems;
	}
	
}
